package com.gjh.service.system.impl;



import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gjh.dao.system.RoleDao;
import com.gjh.domain.system.Role;
import com.gjh.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.SecureRandom;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDao roleDao;
    @Override
    public List<Role> findAll(String companyId ) {
        return roleDao.findAll(companyId);
    }
//保存公司信息
    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    @Override
    public void update(Role role) {
        roleDao.update(role);
    }

    @Override
    public Role findById(String id) {
        return roleDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        roleDao.deleteById(id);
    }

    @Override
    public PageInfo findByPage(String companyId,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Role> list=roleDao.findAll(companyId);
        return new PageInfo(list,5);
    }

    @Override
    public void updateRoleModule(String roleId, String moduleIds) {
        //先删除角色已有的权限
        roleDao.deleteRoleAndModuleByRoleId(roleId);
        //添加用户权限
        String[] mIds = moduleIds.split(",");
        for (String moduleId : mIds) {
            roleDao.saveRoleAndModule(roleId,moduleId);
        }
    }


}
